package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/dish")
@Api(tags = "菜品相关接口")
public class DishController {
    @Autowired
    private DishService dishService;
    @PostMapping
    @ApiOperation("新增菜品")
    public Result addDish(@RequestBody DishDTO dishDTO) {
        dishService.addDish(dishDTO);
        return Result.success();
    }
    @GetMapping("/page")
    @ApiOperation("分页查询")
    public Result findByPage(DishPageQueryDTO dishPageQueryDTO){
        PageResult byPage = dishService.findByPage(dishPageQueryDTO);
        return Result.success(byPage);
    }

    @DeleteMapping
    @ApiOperation("批量删除菜品")
    public Result delete(@RequestParam List<Integer> ids){
        dishService.delete(ids);
        return Result.success();
    }
    @GetMapping("/{dishId}")
    @ApiOperation("根据Id寻找菜品")
    public Result findById(@PathVariable Integer dishId){
        DishVO byId = dishService.findById(dishId);
        return Result.success(byId);
    }
    @PutMapping
    @ApiOperation("修改菜品")
    public Result update(@RequestBody DishVO dishVO){
        dishService.update(dishVO);
        return Result.success();
    }
}
